package net.caidingke.shepherd.domain;

import io.ebean.Model;
import lombok.extern.slf4j.Slf4j;
import net.caidingke.shepherd.utils.mapper.JsonMapper;

import javax.persistence.MappedSuperclass;
import java.util.Map;

/**
 * @author bowen
 */
@MappedSuperclass
public class BaseModel extends Model {

    @SuppressWarnings("unchecked")
    public Map<String, Object> toMap() {
        return (Map<String, Object>) JsonMapper.toMap(this);
    }

    public String toJson() {
        return JsonMapper.toJson(this);
    }

    public static <T> T restore(Map map, Class<T> clazz) {
        return JsonMapper.fromMap(map, clazz);
    }
}
